/*
 * game.cpp
 *
 *  Created on: 2011-9-27
 *  Author    : gelif(admin@gelif.net)
 */
#include "game.h"
#include <wx/string.h>
Coordinate::Coordinate(int x, int y)
{
    this->x = x - 1;
    this->y = y - 1;
}

Coordinate::~Coordinate()
{
}

int Coordinate::getX()
{
    return this->x;
}

void Coordinate::setX(int x)
{
    this->x = x - 1;
}

int Coordinate::getY()
{
    return this->y;
}

void Coordinate::setY(int y)
{
    this->y = y - 1;
}

bool Coordinate::operator<(const Coordinate& coordinate) const
{
    if (this->x < coordinate.x)
        return true;
    else
    {
        if (this->x == coordinate.x && this->y < coordinate.y)
            return true;
        else
            return false;
    }
}

Game::Game()
{
    int x, y;
    for (x = 0; x < MAX_RANKS; x++)
    {
        for (y = 0; y < MAX_FILES; y++)
        {
            this->points[x][y] = Coordinate::NONE;
        }
    }
    this->status = IS_ON;
    this->mypiece = Coordinate::BLACK;
}

Game::~Game()
{
    for (int x = 1; x < MAX_RANKS + 1; x++)
    {
        delete points[x];
    }
    delete[] points;
}

void Game::initStatus()
{
    this->status = IS_READY;
    int x, y;
    for (x = 0; x < MAX_RANKS; x++)
    {
        for (y = 0; y < MAX_FILES; y++)
        {
            this->points[x][y] = Coordinate::NONE;
        }
    }
    this->mypiece = Coordinate::NONE;
}

Game::GameStatus Game::nextStatus()
{
    switch (this->status)
    {
        case IS_WAITING:
            this->status = IS_READY;
            break;
        case IS_READY:
            this->status = IS_ON;
            break;
        case IS_ON:
            this->status = IS_END;
            break;
        case BLACK_WIN:
            this->status = IS_END;
            break;
        case WHITE_WIN:
            this->status = IS_END;
            break;
        default:
            this->status = IS_WAITING;
            break;
    }
    return this->status;
}

void Game::move(int x, int y, Coordinate::Status status)
{
    if (!this->is_my_turn)
    {
        return;
    }
    if (this->points[x][y] == Coordinate::NONE)
    {
        this->points[x][y] = status;
    }
    if (this->status == IS_ON)
    {
        switch (check())
        {
            case Coordinate::BLACK:
                this->status = BLACK_WIN;
                this->mypiece = Coordinate::NONE;
                break;
            case Coordinate::WHITE:
                this->status = WHITE_WIN;
                this->mypiece = Coordinate::NONE;
                break;
            default:
                break;
        }
    }
    this->is_my_turn = false;
}

void Game::move(int x, int y)
{
    move(x, y, this->mypiece);
}

void Game::move(Coordinate coordinate)
{
    move(coordinate.getX(), coordinate.getY());
}

Coordinate::Status Game::check()
{
    // 在横路上
    for (int i = 0; i < MAX_RANKS - 4; ++i)
    {
        for (int j = 0; j < MAX_FILES; ++j)
        {
            if ((points[i][j] == Coordinate::BLACK) && (points[i + 1][j] == Coordinate::BLACK)
                && (points[i + 2][j] == Coordinate::BLACK) && (points[i + 3][j] == Coordinate::BLACK)
                && (points[i + 4][j] == Coordinate::BLACK))
            {
                // 对黑子进行匹配
                fiveline = new Fiveline(i, j, i + 4, j);
                return Coordinate::BLACK;
            }
            else if ((points[i][j] == Coordinate::WHITE) && (points[i + 1][j] == Coordinate::WHITE)
                && (points[i + 2][j] == Coordinate::WHITE) && (points[i + 3][j] == Coordinate::WHITE)
                && (points[i + 4][j] == Coordinate::WHITE))
            {
                // 对白子进行匹配
                fiveline = new Fiveline(i, j, i + 4, j);
                return Coordinate::WHITE;
            }
        }
    }

    // 在纵路上
    for (int i = 0; i < MAX_RANKS; ++i)
    {
        for (int j = 0; j < MAX_FILES - 4; ++j)
        {
            if ((points[i][j] == Coordinate::BLACK) && (points[i][j + 1] == Coordinate::BLACK)
                && (points[i][j + 2] == Coordinate::BLACK) && (points[i][j + 3] == Coordinate::BLACK)
                && (points[i][j + 4] == Coordinate::BLACK))
            {
                // 对黑子进行匹配
                fiveline = new Fiveline(i, j, i, j + 4);
                return Coordinate::BLACK;
            }
            else if ((points[i][j] == 1) && (points[i][j + 1] == 1) && (points[i][j + 2] == 1)
                && (points[i][j + 3] == 1) && (points[i][j + 4] == 1))
            {
                // 对白子进行匹配
                fiveline = new Fiveline(i, j, i, j + 4);
                return Coordinate::WHITE;
            }
        }
    }

    // 在左斜路上
    for (int j = 4; j < MAX_RANKS; ++j)
    {
        for (int i = 0; i < j - 3; ++i)
        {
            if ((points[i][j - i] == Coordinate::BLACK) && (points[i + 1][j - i - 1] == Coordinate::BLACK)
                && (points[i + 2][j - i - 2] == Coordinate::BLACK) && (points[i + 3][j - i - 3] == Coordinate::BLACK)
                && (points[i + 4][j - i - 4] == Coordinate::BLACK))
            {
                // 对黑子进行匹配
                fiveline = new Fiveline(i, j - i, i + 4, j - i - 4);
                return Coordinate::BLACK;
            }
            else if ((points[i][j - i] == Coordinate::WHITE) && (points[i + 1][j - i - 1] == Coordinate::WHITE)
                && (points[i + 2][j - i - 2] == Coordinate::WHITE) && (points[i + 3][j - i - 3] == Coordinate::WHITE)
                && (points[i + 4][j - i - 4] == Coordinate::WHITE))
            {
                // 对白子进行匹配
                fiveline = new Fiveline(i, j - i, i + 4, j - i - 4);
                return Coordinate::WHITE;
            }
        }
    }
    for (int i = 1; i < MAX_RANKS - 4; ++i)
    {
        for (int j = MAX_FILES; j > i + 3; --j)
        {
            if ((points[i + MAX_RANKS - 1 - j][j] == Coordinate::BLACK)
                && (points[i + MAX_RANKS - 1 - j + 1][j - 1] == Coordinate::BLACK)
                && (points[i + MAX_RANKS - 1 - j + 2][j - 2] == Coordinate::BLACK)
                && (points[i + MAX_RANKS - 1 - j + 3][j - 3] == Coordinate::BLACK)
                && (points[i + MAX_RANKS - 1 - j + 4][j - 4] == Coordinate::BLACK))
            {
                // 对黑子进行匹配
                fiveline = new Fiveline(i + MAX_RANKS - 1 - j, j, i + MAX_RANKS - 1 - j + 4, j - 4);
                return Coordinate::BLACK;
            }
            else if ((points[i + MAX_RANKS - 1 - j][j] == Coordinate::WHITE)
                && (points[i + MAX_RANKS - 1 - j + 1][j - 1] == Coordinate::WHITE)
                && (points[i + MAX_RANKS - 1 - j + 2][j - 2] == Coordinate::WHITE)
                && (points[i + MAX_RANKS - 1 - j + 3][j - 3] == Coordinate::WHITE)
                && (points[i + MAX_RANKS - 1 - j + 4][j - 4] == Coordinate::WHITE))
            {
                // 对白子进行匹配
                fiveline = new Fiveline(i + MAX_RANKS - 1 - j, j, i + MAX_RANKS - 1 - j + 4, j - 4);
                return Coordinate::WHITE;
            }
        }
    }

    // 在右斜路上
    for (int j = 4; j < MAX_RANKS; ++j)
    {
        for (int i = 0; i < j - 3; ++i)
        {
            if ((points[MAX_RANKS - 1 - i][j - i] == Coordinate::BLACK)
                && (points[MAX_RANKS - 1 - i - 1][j - i - 1] == Coordinate::BLACK)
                && (points[MAX_RANKS - 1 - i - 2][j - i - 2] == Coordinate::BLACK)
                && (points[MAX_RANKS - 1 - i - 3][j - i - 3] == Coordinate::BLACK)
                && (points[MAX_RANKS - 1 - i - 4][j - i - 4] == Coordinate::BLACK))
            {
                // 对黑子进行匹配
                fiveline = new Fiveline(MAX_RANKS - 1 - i, j - i, MAX_RANKS - 1 - i - 4, j - i - 4);
                return Coordinate::BLACK;
            }
            else if ((points[MAX_RANKS - 1 - i][j - i] == Coordinate::WHITE)
                && (points[MAX_RANKS - 1 - i - 1][j - i - 1] == Coordinate::WHITE)
                && (points[MAX_RANKS - 1 - i - 2][j - i - 2] == Coordinate::WHITE)
                && (points[MAX_RANKS - 1 - i - 3][j - i - 3] == Coordinate::WHITE)
                && (points[MAX_RANKS - 1 - i - 4][j - i - 4] == Coordinate::WHITE))
            {
                // 对白子进行匹配
                fiveline = new Fiveline(MAX_RANKS - 1 - i, j - i, MAX_RANKS - 1 - i - 4, j - i - 4);
                return Coordinate::WHITE;
            }
        }
    }
    for (int i = 1; i < MAX_RANKS - 4; ++i)
    {
        for (int j = MAX_FILES - 1; j > i + 3; --j)
        {
            if ((points[j - i][j] == Coordinate::BLACK) && (points[j - i - 1][j - 1] == Coordinate::BLACK)
                && (points[j - i - 2][j - 2] == Coordinate::BLACK) && (points[j - i - 3][j - 3] == Coordinate::BLACK)
                && (points[j - i - 4][j - 4] == Coordinate::BLACK))
            {
                // 对黑子进行匹配
                fiveline = new Fiveline(j - i, j, j - i - 4, j - 4);
                return Coordinate::BLACK;
            }
            else if ((points[j - i][j] == Coordinate::WHITE) && (points[j - i - 1][j - 1] == Coordinate::WHITE)
                && (points[j - i - 2][j - 2] == Coordinate::WHITE) && (points[j - i - 3][j - 3] == Coordinate::WHITE)
                && (points[j - i - 4][j - 4] == Coordinate::WHITE))
            {
                // 对白子进行匹配
                fiveline = new Fiveline(j - i, j, j - i - 4, j - 4);
                return Coordinate::WHITE;
            }
        }
    }

    return Coordinate::NONE;
}

void Game::resign()
{
    switch (this->mypiece)
    {
        case Coordinate::BLACK:
            this->status = WHITE_WIN;
            break;
        case Coordinate::WHITE:
            this->status = BLACK_WIN;
            break;
        default:
            break;
    }
}

Coordinate::Status Game::getSatusByCoordinate(Coordinate coordinate)
{
    return this->points[coordinate.getX()][coordinate.getY()];
}

wxString Game::serialize() throw ()
{
    //TODO
    return wxT("");
}

void Game::deserialize(wxString&)
{
    //TODO
}

/*
 * 8方向
 * 7   0   1
 * 6   x   2
 * 5   4   3
 *
 * 4方向
 * 0: |   1:   /  2:       3:  \
     *    |       /     ------      \
     *    |      /                   \
    */
Game::ForbiddenStatus Game::checkForbidden(int x, int y)
{
    int adjSame[8]; //记录与(x,y)相邻连续相同黑子数
    int adjEmpty[8]; //记录adjsame后相邻连续空位数
    int jumpSame[8]; //记录adjEmpty后的连续黑子数
    int jumpEmpty[8]; //记录jumpSame后的空位数
    int jumpJumpSame[8]; //记录jumpEmpty后的连续黑子数

    for (int i = 0; i < 8; i++)
    {
        adjSame[i] = adjEmpty[i] = jumpSame[i] = 0;
        jumpEmpty[i] = jumpJumpSame[i] = 0;
    }

    //放入黑子
    this->points[x][y] = Coordinate::BLACK;

    //下面进行棋盘搜索
    int _x_, _y_;

    //向上搜索
    for (_y_ = x - 1; _y_ >= 0 && this->points[x][_y_] == Coordinate::BLACK; _y_--, adjSame[0]++)
        ;
    for (; _y_ >= 0 && this->points[x][_y_] == Coordinate::NONE; _y_--, adjEmpty[0]++)
        ;
    for (; _y_ >= 0 && this->points[x][_y_] == Coordinate::BLACK; _y_--, jumpSame[0]++)
        ;
    for (; _y_ >= 0 && this->points[x][_y_] == Coordinate::NONE; _y_--, jumpEmpty[0]++)
        ;
    for (; _y_ >= 0 && this->points[x][_y_] == Coordinate::BLACK; _y_--, jumpJumpSame[0]++)
        ;

    //右上搜索
    for (_x_ = x + 1, _y_ = x - 1; _x_ < 19 && _y_ >= 0 && this->points[_x_][_y_] == Coordinate::BLACK;
        _x_++, _y_--, adjSame[1]++)
        ;
    for (; _x_ < 19 && _y_ >= 0 && this->points[_x_][_y_] == Coordinate::NONE; _x_++, _y_--, adjEmpty[1]++)
        ;
    for (; _x_ < 19 && _y_ >= 0 && this->points[_x_][_y_] == Coordinate::BLACK; _x_++, _y_--, jumpSame[1]++)
        ;
    for (; _x_ < 19 && _y_ >= 0 && this->points[_x_][_y_] == Coordinate::NONE; _x_++, _y_--, jumpEmpty[1]++)
        ;
    for (; _x_ < 19 && _y_ >= 0 && this->points[_x_][_y_] == Coordinate::BLACK; _x_++, _y_--, jumpJumpSame[1]++)
        ;

    //向右搜索
    for (_x_ = x + 1; _x_ < 19 && this->points[_x_][y] == Coordinate::BLACK; _x_++, adjSame[2]++)
        ;
    for (; _x_ < 19 && _y_ < 19 && this->points[_x_][x] == Coordinate::NONE; _x_++, adjEmpty[2]++)
        ;
    for (; _x_ < 19 && _y_ < 19 && this->points[_x_][x] == Coordinate::BLACK; _x_++, jumpSame[2]++)
        ;
    for (; _x_ < 19 && _y_ < 19 && this->points[_x_][x] == Coordinate::NONE; _x_++, jumpEmpty[2]++)
        ;
    for (; _x_ < 19 && _y_ < 19 && this->points[_x_][x] == Coordinate::BLACK; _x_++, jumpJumpSame[2]++)
        ;

    //向右下搜索
    for (_x_ = x + 1, _y_ = x + 1; _y_ < 19 && this->points[_x_][_y_] == Coordinate::BLACK; _x_++, _y_++, adjSame[3]++)
        ;
    for (; _y_ < 19 && this->points[_x_][_y_] == Coordinate::NONE; _x_++, _y_++, adjEmpty[3]++)
        ;
    for (; _y_ < 19 && this->points[_x_][_y_] == Coordinate::BLACK; _x_++, _y_++, adjSame[3]++)
        ;
    for (; _y_ < 19 && this->points[_x_][_y_] == Coordinate::NONE; _x_++, _y_++, adjEmpty[3]++)
        ;
    for (; _y_ < 19 && this->points[_x_][_y_] == Coordinate::BLACK; _x_++, _y_++, jumpJumpSame[3]++)
        ;

    //向下搜索
    for (_y_ = x + 1; _y_ < 19 && this->points[x][_y_] == Coordinate::BLACK; _y_++, adjSame[4]++)
        ;
    for (; _y_ < 19 && this->points[x][_y_] == Coordinate::NONE; _y_++, adjEmpty[4]++)
        ;
    for (; _y_ < 19 && this->points[x][_y_] == Coordinate::BLACK; _y_++, adjSame[4]++)
        ;
    for (; _y_ < 19 && this->points[x][_y_] == Coordinate::NONE; _y_++, adjEmpty[4]++)
        ;
    for (; _y_ < 19 && this->points[x][_y_] == Coordinate::BLACK; _y_++, jumpJumpSame[4]++)
        ;

    //向左下搜索
    for (_x_ = x - 1, _y_ = x + 1; _y_ < 19 && this->points[_x_][_y_] == Coordinate::BLACK; _x_--, _y_++, adjSame[5]++)
        ;
    for (; _y_ < 19 && this->points[_x_][_y_] == Coordinate::NONE; _x_--, _y_++, adjEmpty[5]++)
        ;
    for (; _y_ < 19 && this->points[_x_][_y_] == Coordinate::BLACK; _x_--, _y_++, adjSame[5]++)
        ;
    for (; _y_ < 19 && this->points[_x_][_y_] == Coordinate::NONE; _x_--, _y_++, adjEmpty[5]++)
        ;
    for (; _y_ < 19 && this->points[_x_][_y_] == Coordinate::BLACK; _x_--, _y_++, jumpJumpSame[5]++)
        ;

    //向左搜索
    for (_x_ = x - 1; _x_ >= 0 && this->points[_x_][x] == Coordinate::BLACK; _x_--, adjSame[6]++)
        ;
    for (; _y_ < 19 && this->points[_x_][x] == Coordinate::NONE; _x_--, adjEmpty[6]++)
        ;
    for (; _y_ < 19 && this->points[_x_][x] == Coordinate::BLACK; _x_--, adjSame[6]++)
        ;
    for (; _y_ < 19 && this->points[_x_][x] == Coordinate::NONE; _x_--, adjEmpty[6]++)
        ;
    for (; _y_ < 19 && this->points[_x_][x] == Coordinate::BLACK; _x_--, jumpJumpSame[6]++)
        ;

    //向左上搜索
    for (_y_ = x + 1; _y_ < 19 && this->points[x][_y_] == Coordinate::BLACK; _x_--, _y_--, adjSame[7]++)
        ;
    for (; _y_ < 19 && this->points[x][_y_] == Coordinate::NONE; _x_--, _y_--, adjEmpty[7]++)
        ;
    for (; _y_ < 19 && this->points[x][_y_] == Coordinate::BLACK; _x_--, _y_--, adjSame[7]++)
        ;
    for (; _y_ < 19 && this->points[x][_y_] == Coordinate::NONE; _x_--, _y_--, adjEmpty[7]++)
        ;
    for (; _y_ < 19 && this->points[x][_y_] == Coordinate::BLACK; _x_--, _y_--, jumpJumpSame[7]++)
        ;

    //--搜索完毕--

    //将棋盘还原
    this->points[x][x] = Coordinate::NONE;

    //先检查是否成连五，若连五，无禁手
    for (int i = 0; i < 4; i++)
    {
        if (adjSame[i] + adjSame[i + 4] == 4)
        {
            return NO;
        }
    }

    //禁手分析
    int threeInrowCount = 0, fourInrowCount = 0; //棋型统计数

    for (int i = 0; i < 4; i++)
    {
        if (adjSame[i] + adjSame[i + 4] >= 5) //五子以上相连
            return LONG; // 长连禁手
        else if (adjSame[i] + adjSame[i + 4] == 3) //四字相连
        {
            //活四冲四判断
            bool isFour = false;
            if (adjEmpty[i] > 0)
            {
                if (checkForbidden(Coordinate(x, y), adjSame[i], i) == NO)
                    isFour = true;
            }

            if (adjEmpty[i + 4] > 0) //?0000+?
            {
                if (checkForbidden(Coordinate(x, y), adjSame[i + 4], i + 4) == NO)
                    isFour = true;
            }
            if (isFour)
                fourInrowCount++;

        }
        else if (adjSame[i] + adjSame[i + 4] == 2) //三子相连 ?●●●?
        {
            //活四冲四检查
            if (adjEmpty[i] == 1 && jumpSame[i] == 1) // ?●+●●●?
            {
                if (checkForbidden(Coordinate(x, y), adjSame[i], i) == NO)
                    fourInrowCount++;
            }
            if (adjEmpty[i + 4] == 1 && jumpSame[i + 4] == 1) // ?●+●●●?
            {
                if (checkForbidden(Coordinate(x, y), adjSame[i + 4], i + 4) == NO)
                    fourInrowCount++;
            }

            bool isThree = false;

            // ?+●●●+?
            if ((adjEmpty[i] > 2 || (adjEmpty[i] == 2 && adjSame[i] == 0))
                && (adjEmpty[i + 4] > 1 || (adjEmpty[i + 4] == 1 && jumpSame[i + 4] == 0)))
            {
                if (checkForbidden(Coordinate(x, y), adjSame[i], i) == NO)
                    isThree = true;
            }

            if (isThree)
                threeInrowCount++;
        }
        else if (adjSame[i] + adjSame[i + 4] == 1) // 两子相连 ?●●?
        {
            //活四冲四判断
            if (adjEmpty[i] == 1 && jumpSame[i] == 2) // ?●●+●●?
            {
                if (checkForbidden(Coordinate(x, y), adjSame[i], i) == NO)
                {
                    fourInrowCount++;
                }
            }

            if (adjEmpty[i + 4] == 1 && jumpSame[i + 4] == 2) // ?●●+●●?
            {
                if (checkForbidden(Coordinate(x, y), adjSame[i], i) == NO)
                {
                    fourInrowCount++;
                }
            }

            //活三判断
            if (adjEmpty[i] == 1 && jumpSame[i] == 1
                && (jumpEmpty[i] > 1 || (jumpEmpty[i] == 1 && jumpJumpSame[i] == 0))
                && (adjEmpty[i + 4] > 1 || (adjEmpty[i + 4] == 1 && jumpSame[i + 4] == 0))) // ?+●+●●+?
            {
                if (checkForbidden(Coordinate(x, y), adjSame[i], i) == NO)
                {
                    threeInrowCount++;
                }
            }

            if (adjEmpty[i + 4] == 1 && jumpSame[i + 4] == 1
                && (jumpEmpty[i + 4] > 1 || (jumpEmpty[i + 4] == 1 && jumpJumpSame[i + 4] == 0))
                && (adjEmpty[i] > 1 || (adjEmpty[i] == 1 && jumpSame[i] == 0))) // ?+●●+●+?
            {
                if (checkForbidden(Coordinate(x, y), adjSame[i + 4], i + 4) == NO)
                {
                    threeInrowCount++;
                }
            }
        }
        else if (adjSame[i] + adjSame[i + 4] == 0) //单独一子 ?●?
        {
            //活四冲四判断
            if (adjEmpty[i] == 1 && jumpSame[i] == 3) //?●●●+●?
            {
                if (checkForbidden(Coordinate(x, y), adjSame[i], i) == NO)
                {
                    fourInrowCount++;
                }
            }
            if (adjEmpty[i + 4] == 1 && jumpSame[i + 4] == 3) //?●+●●●?
            {
                if (checkForbidden(Coordinate(x, y), adjSame[i + 4], i + 4) == NO)
                {
                    fourInrowCount++;
                }
            }

            //活三判断
            if (adjEmpty[i] == 1 && jumpSame[i] == 2
                && (jumpEmpty[i] > 1 || (jumpEmpty[i] == 1 && jumpJumpSame[i] == 0))
                && (adjEmpty[i + 4] > 1 || (adjEmpty[i + 4] == 1 && jumpSame[i + 4] == 0))) //?●●●+●?
            {
                if (checkForbidden(Coordinate(x, y), adjSame[i], i) == NO)
                {
                    fourInrowCount++;
                }
            }
            if (adjEmpty[i + 4] == 1 && jumpSame[i + 4] == 2
                && (jumpEmpty[i + 4] > 1 || (jumpEmpty[i + 4] == 1 && jumpJumpSame[i + 4] == 0))
                && (adjEmpty[i] > 1 || (adjEmpty[i] == 1 && jumpSame[i] == 0))) //?+●+●●+?
            {
                if (checkForbidden(Coordinate(x, y), adjSame[i + 4], i + 4) == NO)
                {
                    fourInrowCount++;
                }
            }
        }
    }

    //--禁手分析结束--

    if (fourInrowCount > 1)
        return FOUR_FOUR;
    if (threeInrowCount > 1)
        return THREE_THREE;
    return NO;
}

Game::ForbiddenStatus Game::checkForbidden(Coordinate coordinate, int adjSame, int direction)
{
    int x, y; // 关键点坐标(x, y)
    adjSame++;
    if (direction >= 4)
    {
        adjSame = -adjSame;
    }

    //计算关键点坐标
    switch (direction % 4)
    {
        case 0:
            x = coordinate.getX();
            y = coordinate.getY() - adjSame;
            break;
        case 1:
            x = coordinate.getX() + adjSame;
            y = coordinate.getY() - adjSame;
            break;
        default:
            x = coordinate.getX() + adjSame;
            y = coordinate.getY() + adjSame;
            break;
    }

    //向棋盘放入棋子
    this->points[coordinate.getX()][coordinate.getY()] = Coordinate::BLACK;
    this->points[x][y] = Coordinate::BLACK;

    //检查关键点
    ForbiddenStatus forbiddenStatus = Game::checkForbidden(x, y);

    //还原棋盘
    this->points[coordinate.getX()][coordinate.getY()] = Coordinate::NONE;
    this->points[x][y] = Coordinate::NONE;

    return forbiddenStatus;
}

/*
 Step& Game::restore()
 {
 Step& step = this->steps.top();
 this->steps.pop();
 return step;
 }
 */

Fiveline::Fiveline(int startX, int startY, int endX, int endY)
{
    this->startX = startX;
    this->startY = startY;
    this->endX = endX;
    this->endY = endY;
}

Fiveline::~Fiveline()
{
}

GelifMove::GelifMove(int x, int y, Coordinate::Status status)
{
    this->x = x;
    this->y = y;
    this->status = status;
}

GelifMove::GelifMove(wxChar* charArray)
{
    this->deserialize(charArray);
}

GelifMove::~GelifMove()
{
}

wxChar* GelifMove::serialize() throw ()
{
    wchar_t* str = new wchar_t[3];

    if (this->x > 9)
    {
        str[0] = '0' + this->x + 7;
    }
    else
    {
        str[0] = '0' + this->x;
    }
    if (this->y > 9)
    {
        str[1] = '0' + this->y + 7;
    }
    else
    {
        str[1] = '0' + this->y;
    }
    int int_status = this->status;
    str[2] = '0' + int_status;
    return str;
}

void GelifMove::deserialize(wxChar* charArray)
{
    if (charArray[0] > '9')
    {
        this->x = charArray[0] - '0' - 7;
    }
    else
    {
        this->x = charArray[0] - '0';
    }
    if (charArray[1] > '9')
    {
        this->y = charArray[1] - '0' - 7;
    }
    else
    {
        this->y = charArray[1] - '0';
    }
    int int_status = charArray[2] - '0';
    switch (int_status)
    {
        case 0:
            this->status = Coordinate::NONE;
            break;
        case 1:
            this->status = Coordinate::BLACK;
            break;
        case 2:
            this->status = Coordinate::WHITE;
            break;
    }
}
